import { SettingPermissionService } from 'services/Api'

/* 状态相关（恢复禁用按钮）
-------------------------- */
export const StatusMixin = {
  computed: {
    // 捎货类型 禁用,解禁参数
    alterAdminGroupStatusParam () {
      return {
        acc_id: this.acc_id,
        ids: this.selectIds,
        status: this.status
      }
    }
  },
  methods: {
    // 改变捎货类型状态接口
    currentStatusApi () {
      return SettingPermissionService.alterAdminGroupStatus(this.alterAdminGroupStatusParam)
    }
  }
}

/* 打开配置规则
-------------------------- */
export const RulesMixin = {
  data () {
    return {
      showRuleDialogByToggle: false,
      groupRulesData: {},
      groupId: ''
    }
  },
  computed: {
    groupAccessParam () {
      return {
        acc_id: this.acc_id,
        group_id: this.groupId
      }
    }
  },
  methods: {
    getRules (id, index) {
      this.groupId = id
      this.AsyncLoading('配置规则', index, this.groupAccess)
    },
    // 获取用户组拥有的权限列表
    async groupAccess () {
      const [ err, res ] = await SettingPermissionService.groupAccess(this.groupAccessParam)
      if (err) return this.$message.error('获取用户组拥有的权限列表失败')
      this.groupRulesData = { rules: res.list, id: this.groupId }
      this.showRuleDialogByToggle = !this.showRuleDialogByToggle
    }
  }
}
